//网络请求
import axios from 'axios';
import AppConfig from '@/constants/AppConfig.js';

const $axios = axios;

export default function() {
	var $app_config = AppConfig();
	var $base_url = $app_config.Base_Url;
	var $post_config = $app_config.POST_Cfg;
	
	//获取作品筛选条件
	var $url_get_worksFilters = $base_url + "/admin/works/v1/getWorksFilters";
	//获取作品
	var $url_get_works = $base_url + "/admin/works/v1/getWorks";
	var $url_get_works2User = $base_url + "/admin/works/v1/getWorks2User";
	var $url_get_worksDetail = $base_url + "/admin/works/v1/getWorksDetail";
	//草稿箱、待审核作品、驳回作品
	var $url_get_works2Status = $base_url + "/admin/works/v1/getWorks2Status";
	var $url_get_works2Wait = $base_url + "/admin/works/v1/getWorks2Wait";
	//提交审核、审核、驳回
	var $url_submit2Verify = $base_url + "/admin/works/v1/submit2Verify";
	var $url_publish = $base_url + "/admin/works/v1/publish";
	var $url_reject = $base_url + "/admin/works/v1/reject";
	var $url_del_works = $base_url + "/admin/works/v1/delWorks";
	
	var $url_edit_works = $base_url + "/admin/works/v1/editWorks";
	return {
		editWorks: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_edit_works, {
					worksId: params.worksId,//	string	32位数字字母	作品id
					attribute: params.attribute, //	string	0	作品属性
					name	: params.name, //String	作品名称	作品名称
					types: params.types, //	string	['','']	类型
					poster: params.poster, // 	string	海报地址	类型
					dateType: params.dateType,
					releaseDate: params.releaseDate,//	string	1900-09-01	上映日期
					releaseYear: params.releaseYear, //	string	1900	上映年份
					releaseArea: params.releaseArea, //		int	1	上映地区
					areaName: params.areaName,
					duration	: params.duration, //	int	90	片长
					boxOffice: params.boxOffice, //		int	3200	1000万元
					episodes: params.episodes, //		int	10	集数
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getWorksFilters: function() {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_worksFilters, {}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getWorks: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_works, params, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		submit2Verify: function(wid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_submit2Verify, {
					wid: wid
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		delWorks: function(wid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_del_works, {
					wid: wid
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		publish: function(wid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_publish, {
					wid: wid
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		reject: function(wid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_reject, {
					wid: wid
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getWorks2Status: function(params) {
			return new Promise(function(resolve, reject) {
				console.log(params);
				$axios.post($url_get_works2Status, {
					key: params.key,
					status: params.status,
					page: params.page,
					pagesize: params.pagesize
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getWorks2Wait: function(params) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_works2Wait, {
					key: params.key,
					page: params.page,
					pagesize: params.pagesize
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getWorks2User: function(userId) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_works2User, {
					userId: userId
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		},
		getWorksDetail: function(wid) {
			return new Promise(function(resolve, reject) {
				$axios.post($url_get_worksDetail, {
					wid: wid
				}, $post_config)
					.then(function(response) {
						console.log(response);
						resolve(response);
					})
					.catch(function(err) {
						reject(err);
					});
			});
		}
	}
}